package com.example.demo.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.example.demo.properties.TestProperties;
import com.example.demo.service.Test1ServiceImpl;
import com.example.demo.service.Test2ServiceImpl;
import com.example.demo.service.TestService;

@EnableConfigurationProperties(TestProperties.class)
@Configuration
public class TestConfiguration {
	
	@Autowired
	private TestProperties testProperties;
	
	@ConditionalOnMissingBean(TestService.class)
	@Bean
	public Test2ServiceImpl getTest2Service() {
		System.out.println(testProperties.getVersion());
		return new Test2ServiceImpl();
	}
	
	@ConditionalOnMissingBean(TestService.class)
	@Bean
	public Test1ServiceImpl getTest1Service() {
		System.out.println(testProperties.getId());
		return new Test1ServiceImpl();
	}

}
